<?php


abstract class BaseRingtoneExtra extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $ringtone_id;


	
	protected $rt_code;


	
	protected $rbt_id;


	
	protected $rbt_code;


	
	protected $size;


	
	protected $price = -1;


	
	protected $rt_price = -1;


	
	protected $rbt_price = -1;


	
	protected $origin_id;


	
	protected $origin_from;


	
	protected $origin_to;


	
	protected $description;


	
	protected $upload_datetime;


	
	protected $rbt_long_code;


	
	protected $valid_datetime;


	
	protected $contract_index;


	
	protected $contract_index_number;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getRingtoneId()
	{

		return $this->ringtone_id;
	}

	
	public function getRtCode()
	{

		return $this->rt_code;
	}

	
	public function getRbtId()
	{

		return $this->rbt_id;
	}

	
	public function getRbtCode()
	{

		return $this->rbt_code;
	}

	
	public function getSize()
	{

		return $this->size;
	}

	
	public function getPrice()
	{

		return $this->price;
	}

	
	public function getRtPrice()
	{

		return $this->rt_price;
	}

	
	public function getRbtPrice()
	{

		return $this->rbt_price;
	}

	
	public function getOriginId()
	{

		return $this->origin_id;
	}

	
	public function getOriginFrom()
	{

		return $this->origin_from;
	}

	
	public function getOriginTo()
	{

		return $this->origin_to;
	}

	
	public function getDescription()
	{

		return $this->description;
	}

	
	public function getUploadDatetime($format = 'Y-m-d H:i:s')
	{

		if ($this->upload_datetime === null || $this->upload_datetime === '') {
			return null;
		} elseif (!is_int($this->upload_datetime)) {
						$ts = strtotime($this->upload_datetime);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [upload_datetime] as date/time value: " . var_export($this->upload_datetime, true));
			}
		} else {
			$ts = $this->upload_datetime;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getRbtLongCode()
	{

		return $this->rbt_long_code;
	}

	
	public function getValidDatetime($format = 'Y-m-d H:i:s')
	{

		if ($this->valid_datetime === null || $this->valid_datetime === '') {
			return null;
		} elseif (!is_int($this->valid_datetime)) {
						$ts = strtotime($this->valid_datetime);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [valid_datetime] as date/time value: " . var_export($this->valid_datetime, true));
			}
		} else {
			$ts = $this->valid_datetime;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getContractIndex()
	{

		return $this->contract_index;
	}

	
	public function getContractIndexNumber()
	{

		return $this->contract_index_number;
	}

	
	public function setRingtoneId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->ringtone_id !== $v) {
			$this->ringtone_id = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::RINGTONE_ID;
		}

	} 
	
	public function setRtCode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->rt_code !== $v) {
			$this->rt_code = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::RT_CODE;
		}

	} 
	
	public function setRbtId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->rbt_id !== $v) {
			$this->rbt_id = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::RBT_ID;
		}

	} 
	
	public function setRbtCode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->rbt_code !== $v) {
			$this->rbt_code = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::RBT_CODE;
		}

	} 
	
	public function setSize($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->size !== $v) {
			$this->size = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::SIZE;
		}

	} 
	
	public function setPrice($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->price !== $v || $v === -1) {
			$this->price = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::PRICE;
		}

	} 
	
	public function setRtPrice($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->rt_price !== $v || $v === -1) {
			$this->rt_price = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::RT_PRICE;
		}

	} 
	
	public function setRbtPrice($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->rbt_price !== $v || $v === -1) {
			$this->rbt_price = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::RBT_PRICE;
		}

	} 
	
	public function setOriginId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->origin_id !== $v) {
			$this->origin_id = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::ORIGIN_ID;
		}

	} 
	
	public function setOriginFrom($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->origin_from !== $v) {
			$this->origin_from = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::ORIGIN_FROM;
		}

	} 
	
	public function setOriginTo($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->origin_to !== $v) {
			$this->origin_to = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::ORIGIN_TO;
		}

	} 
	
	public function setDescription($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->description !== $v) {
			$this->description = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::DESCRIPTION;
		}

	} 
	
	public function setUploadDatetime($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [upload_datetime] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->upload_datetime !== $ts) {
			$this->upload_datetime = $ts;
			$this->modifiedColumns[] = RingtoneExtraPeer::UPLOAD_DATETIME;
		}

	} 
	
	public function setRbtLongCode($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->rbt_long_code !== $v) {
			$this->rbt_long_code = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::RBT_LONG_CODE;
		}

	} 
	
	public function setValidDatetime($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [valid_datetime] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->valid_datetime !== $ts) {
			$this->valid_datetime = $ts;
			$this->modifiedColumns[] = RingtoneExtraPeer::VALID_DATETIME;
		}

	} 
	
	public function setContractIndex($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->contract_index !== $v) {
			$this->contract_index = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::CONTRACT_INDEX;
		}

	} 
	
	public function setContractIndexNumber($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->contract_index_number !== $v) {
			$this->contract_index_number = $v;
			$this->modifiedColumns[] = RingtoneExtraPeer::CONTRACT_INDEX_NUMBER;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->ringtone_id = $rs->getInt($startcol + 0);

			$this->rt_code = $rs->getString($startcol + 1);

			$this->rbt_id = $rs->getInt($startcol + 2);

			$this->rbt_code = $rs->getString($startcol + 3);

			$this->size = $rs->getString($startcol + 4);

			$this->price = $rs->getInt($startcol + 5);

			$this->rt_price = $rs->getInt($startcol + 6);

			$this->rbt_price = $rs->getInt($startcol + 7);

			$this->origin_id = $rs->getInt($startcol + 8);

			$this->origin_from = $rs->getInt($startcol + 9);

			$this->origin_to = $rs->getInt($startcol + 10);

			$this->description = $rs->getString($startcol + 11);

			$this->upload_datetime = $rs->getTimestamp($startcol + 12, null);

			$this->rbt_long_code = $rs->getString($startcol + 13);

			$this->valid_datetime = $rs->getTimestamp($startcol + 14, null);

			$this->contract_index = $rs->getString($startcol + 15);

			$this->contract_index_number = $rs->getString($startcol + 16);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 17; 
		} catch (Exception $e) {
			throw new PropelException("Error populating RingtoneExtra object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(RingtoneExtraPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			RingtoneExtraPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(RingtoneExtraPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = RingtoneExtraPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setNew(false);
				} else {
					$affectedRows += RingtoneExtraPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = RingtoneExtraPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = RingtoneExtraPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getRingtoneId();
				break;
			case 1:
				return $this->getRtCode();
				break;
			case 2:
				return $this->getRbtId();
				break;
			case 3:
				return $this->getRbtCode();
				break;
			case 4:
				return $this->getSize();
				break;
			case 5:
				return $this->getPrice();
				break;
			case 6:
				return $this->getRtPrice();
				break;
			case 7:
				return $this->getRbtPrice();
				break;
			case 8:
				return $this->getOriginId();
				break;
			case 9:
				return $this->getOriginFrom();
				break;
			case 10:
				return $this->getOriginTo();
				break;
			case 11:
				return $this->getDescription();
				break;
			case 12:
				return $this->getUploadDatetime();
				break;
			case 13:
				return $this->getRbtLongCode();
				break;
			case 14:
				return $this->getValidDatetime();
				break;
			case 15:
				return $this->getContractIndex();
				break;
			case 16:
				return $this->getContractIndexNumber();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = RingtoneExtraPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getRingtoneId(),
			$keys[1] => $this->getRtCode(),
			$keys[2] => $this->getRbtId(),
			$keys[3] => $this->getRbtCode(),
			$keys[4] => $this->getSize(),
			$keys[5] => $this->getPrice(),
			$keys[6] => $this->getRtPrice(),
			$keys[7] => $this->getRbtPrice(),
			$keys[8] => $this->getOriginId(),
			$keys[9] => $this->getOriginFrom(),
			$keys[10] => $this->getOriginTo(),
			$keys[11] => $this->getDescription(),
			$keys[12] => $this->getUploadDatetime(),
			$keys[13] => $this->getRbtLongCode(),
			$keys[14] => $this->getValidDatetime(),
			$keys[15] => $this->getContractIndex(),
			$keys[16] => $this->getContractIndexNumber(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = RingtoneExtraPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setRingtoneId($value);
				break;
			case 1:
				$this->setRtCode($value);
				break;
			case 2:
				$this->setRbtId($value);
				break;
			case 3:
				$this->setRbtCode($value);
				break;
			case 4:
				$this->setSize($value);
				break;
			case 5:
				$this->setPrice($value);
				break;
			case 6:
				$this->setRtPrice($value);
				break;
			case 7:
				$this->setRbtPrice($value);
				break;
			case 8:
				$this->setOriginId($value);
				break;
			case 9:
				$this->setOriginFrom($value);
				break;
			case 10:
				$this->setOriginTo($value);
				break;
			case 11:
				$this->setDescription($value);
				break;
			case 12:
				$this->setUploadDatetime($value);
				break;
			case 13:
				$this->setRbtLongCode($value);
				break;
			case 14:
				$this->setValidDatetime($value);
				break;
			case 15:
				$this->setContractIndex($value);
				break;
			case 16:
				$this->setContractIndexNumber($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = RingtoneExtraPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setRingtoneId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setRtCode($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setRbtId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setRbtCode($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setSize($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setPrice($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setRtPrice($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setRbtPrice($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setOriginId($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setOriginFrom($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setOriginTo($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setDescription($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setUploadDatetime($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setRbtLongCode($arr[$keys[13]]);
		if (array_key_exists($keys[14], $arr)) $this->setValidDatetime($arr[$keys[14]]);
		if (array_key_exists($keys[15], $arr)) $this->setContractIndex($arr[$keys[15]]);
		if (array_key_exists($keys[16], $arr)) $this->setContractIndexNumber($arr[$keys[16]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(RingtoneExtraPeer::DATABASE_NAME);

		if ($this->isColumnModified(RingtoneExtraPeer::RINGTONE_ID)) $criteria->add(RingtoneExtraPeer::RINGTONE_ID, $this->ringtone_id);
		if ($this->isColumnModified(RingtoneExtraPeer::RT_CODE)) $criteria->add(RingtoneExtraPeer::RT_CODE, $this->rt_code);
		if ($this->isColumnModified(RingtoneExtraPeer::RBT_ID)) $criteria->add(RingtoneExtraPeer::RBT_ID, $this->rbt_id);
		if ($this->isColumnModified(RingtoneExtraPeer::RBT_CODE)) $criteria->add(RingtoneExtraPeer::RBT_CODE, $this->rbt_code);
		if ($this->isColumnModified(RingtoneExtraPeer::SIZE)) $criteria->add(RingtoneExtraPeer::SIZE, $this->size);
		if ($this->isColumnModified(RingtoneExtraPeer::PRICE)) $criteria->add(RingtoneExtraPeer::PRICE, $this->price);
		if ($this->isColumnModified(RingtoneExtraPeer::RT_PRICE)) $criteria->add(RingtoneExtraPeer::RT_PRICE, $this->rt_price);
		if ($this->isColumnModified(RingtoneExtraPeer::RBT_PRICE)) $criteria->add(RingtoneExtraPeer::RBT_PRICE, $this->rbt_price);
		if ($this->isColumnModified(RingtoneExtraPeer::ORIGIN_ID)) $criteria->add(RingtoneExtraPeer::ORIGIN_ID, $this->origin_id);
		if ($this->isColumnModified(RingtoneExtraPeer::ORIGIN_FROM)) $criteria->add(RingtoneExtraPeer::ORIGIN_FROM, $this->origin_from);
		if ($this->isColumnModified(RingtoneExtraPeer::ORIGIN_TO)) $criteria->add(RingtoneExtraPeer::ORIGIN_TO, $this->origin_to);
		if ($this->isColumnModified(RingtoneExtraPeer::DESCRIPTION)) $criteria->add(RingtoneExtraPeer::DESCRIPTION, $this->description);
		if ($this->isColumnModified(RingtoneExtraPeer::UPLOAD_DATETIME)) $criteria->add(RingtoneExtraPeer::UPLOAD_DATETIME, $this->upload_datetime);
		if ($this->isColumnModified(RingtoneExtraPeer::RBT_LONG_CODE)) $criteria->add(RingtoneExtraPeer::RBT_LONG_CODE, $this->rbt_long_code);
		if ($this->isColumnModified(RingtoneExtraPeer::VALID_DATETIME)) $criteria->add(RingtoneExtraPeer::VALID_DATETIME, $this->valid_datetime);
		if ($this->isColumnModified(RingtoneExtraPeer::CONTRACT_INDEX)) $criteria->add(RingtoneExtraPeer::CONTRACT_INDEX, $this->contract_index);
		if ($this->isColumnModified(RingtoneExtraPeer::CONTRACT_INDEX_NUMBER)) $criteria->add(RingtoneExtraPeer::CONTRACT_INDEX_NUMBER, $this->contract_index_number);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(RingtoneExtraPeer::DATABASE_NAME);

		$criteria->add(RingtoneExtraPeer::RINGTONE_ID, $this->ringtone_id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getRingtoneId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setRingtoneId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setRtCode($this->rt_code);

		$copyObj->setRbtId($this->rbt_id);

		$copyObj->setRbtCode($this->rbt_code);

		$copyObj->setSize($this->size);

		$copyObj->setPrice($this->price);

		$copyObj->setRtPrice($this->rt_price);

		$copyObj->setRbtPrice($this->rbt_price);

		$copyObj->setOriginId($this->origin_id);

		$copyObj->setOriginFrom($this->origin_from);

		$copyObj->setOriginTo($this->origin_to);

		$copyObj->setDescription($this->description);

		$copyObj->setUploadDatetime($this->upload_datetime);

		$copyObj->setRbtLongCode($this->rbt_long_code);

		$copyObj->setValidDatetime($this->valid_datetime);

		$copyObj->setContractIndex($this->contract_index);

		$copyObj->setContractIndexNumber($this->contract_index_number);


		$copyObj->setNew(true);

		$copyObj->setRingtoneId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new RingtoneExtraPeer();
		}
		return self::$peer;
	}

} 